<?php

    include 'template/header.html';
    require_once 'lib/function.php';

    $action = isset($_GET['action'])?$_GET['action']:'list';
    switch ($action) {
        case 'list':

            $sql = "SELECT
customer.c_id,
customer.c_name,
customer.c_comment,
customer.c_addtime,
customersource.csource_info,
customertype.ctype_info,
customer.c_company,
customerstat.cstat_stat
FROM
customer
INNER JOIN customersource ON customersource.csource_id = customer.csource_id
INNER JOIN customertype ON customertype.ctype_id = customer.ctype_id
INNER JOIN customerstat ON customerstat.cstat_id = customer.cstat_id
where customer.e_id not in (select e_id from employee)";
             $rowNum = getRowNum($sql);
            $page = isset($_GET['page'])?$_GET['page']:1;
            $listNum = 10;
            $maxPage = ceil($rowNum/$listNum);
            $res = page($page,$sql, $listNum);
            include 'template/customer_allot_list.html';
            break;
        case 'allot':
            $id = $_GET['id'];
            $sql = "select c_name,c_id from customer where c_id='$id'";
            $res = getAllData($sql);
            $res = $res[0];
        $sql1 = "select e_id,e_name from employee";
         $cArr = getAllData($sql1);
            include 'template/customer_allot_add.html';
            break;
        case 'allot_check':

            $cname = $_POST['cname'];
            $cid = $_POST['cid'];
            $eid = $_POST['ename']+0;
            $sql = "update customer set e_id='$eid' where c_id='$cid'";
            // echo $sql;
            // exit;
            if(dclData($sql)>0){
                echo "<script>alert('分配成功！');location.href='c_action.php'</script>";
            }
             echo "<script>alert('分配失败！');location.href='allot.php'</script>";
            break;
    }
    include 'template/foot.html';